/*
 * 项目名称:cx-server
 * 类名称:KbDirectoryController.java
 * 包名称:com.ft.oa.modules.kb.controller
 *
 * 修改履历:
 *     日期                       修正者        主要内容
 *     2022-01-18 11:36:00        zw     初版做成
 *
 * Copyright (c) 2019-2019 启元软件
 */
package com.ft.oa.web.knowledgeBase;

import com.ft.oa.domain.dto.ApiResult;
import com.ft.oa.domain.dto.knowledgeBase.AttachmentDto;
import com.ft.oa.domain.dto.knowledgeBase.KBPage;
import com.ft.oa.domain.knowledgeBase.Directory;
import com.ft.oa.service.knowledgeBase.DirectoryService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

/**
 * 知识库目录表Controller
 *
 * @author zw
 * @date 2022-01-18 11:36:00
 */
@RestController
@RequestMapping("kb/directory")
public class DirectoryController
{
    @Autowired
    private DirectoryService directoryService;

    /**
     * 根据主键查询详情
     *
     * @param id 主键
     * @return RestResponse
     */
    @RequestMapping("/info/{id}")
    public ApiResult info(@PathVariable("id") Long id)
    {
        return ApiResult.simpleSuccess();
    }

    /**
     * 新增知识库目录表
     *
     * @param directory
     * @return RestResponse
     */
    @RequestMapping("/save")
    public ApiResult save(@RequestBody Directory directory)
    {
        directoryService.add(directory);
        return ApiResult.simpleSuccess();
    }

    /**
     * 修改知识库目录表
     *
     * @param directory
     * @return RestResponse
     */
    @RequestMapping("/update")
    public ApiResult update(@RequestBody Directory directory)
    {
        directoryService.update(directory);
        return ApiResult.simpleSuccess();
    }

    /**
     * 根据主键删除知识库目录表
     *
     * @param id
     * @return RestResponse
     */
    @RequestMapping("/delete")
    public ApiResult delete(@RequestBody Long id)
    {
        directoryService.remove(id);
        return ApiResult.simpleSuccess();
    }

    /**
     * 获取知识库数据列表
     *
     * @return
     */
    @RequestMapping("/getDirectoryList")
    public ApiResult getDirectoryList()
    {
        return ApiResult.successWithData(directoryService.getDirectoryList());
    }

    /**
     * 获取附件列表分页
     *
     * @param kbPage
     * @return
     */
    @RequestMapping("/getAttList")
    public ApiResult getAttList(@RequestBody KBPage kbPage)
    {
        return ApiResult.successWithData(directoryService.getAttList(kbPage));
    }

    /**
     * 获取 项目的附件列表
     *
     * @param kbPage
     * @return
     */
    @RequestMapping("/getAttProList")
    public ApiResult getAttProList(@RequestBody KBPage kbPage)
    {
        return ApiResult.successWithData(directoryService.getAttProList(kbPage));
    }

    /**
     * 获取 知识库目录树结构
     *
     * @param id
     * @return
     */
    @RequestMapping("/getDirectoryTree/{id}")
    public ApiResult getDirectoryTree(@PathVariable("id") Long id)
    {
        return ApiResult.successWithData(directoryService.getDirectoryTree(id));
    }

    /**
     * 知识库文件上传保存附件
     * @param attachmentDto
     * @return
     */
    @RequestMapping("/upload")
    public ApiResult upload(@RequestBody AttachmentDto attachmentDto)
    {
        directoryService.saveAttachment(attachmentDto);
        return ApiResult.simpleSuccess();
    }

}
